# 异常的捕获
try:
    # print(1 / 0)
    print("hello world")
    # print(a)
   
except NameError:
    print("变量不存在")
except Exception as e: # 捕获所有异常
    print(e)
else:
    print("没有异常发生")
finally:
    print("无论是否发生异常，都会执行")


# 自定义异常
class MyException(Exception):
    def __init__(self, message):
        self.message = message

def add(*args):
    if len(args) == 1:
        raise MyException("参数个数不正确")
    r = 0
    for i in args:
        r += i
    print(r)

try:
    add(1,2,3)
    add(1)
except MyException as e:
    print(e.message)

print("后面可以正常的执行")